package cn.school.controller.teacher.evaluation;

import cn.school.common.annotation.SysLog;
import cn.school.common.api.CommonResult;
import cn.school.common.enums.BusinessType;
import cn.school.teacher.evaluation.service.EvaluationItemService;
import cn.school.teacher.evaluation.vo.ItemNodeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = {"EvaluationItemController => 考评项管理"})
@RequestMapping("/teacher/evaluation/item")
public class EvaluationItemController {
    @Autowired
    private EvaluationItemService evaluationItemService;

    @ApiOperation("/list/{id} => 获取考评方案的考评项")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:query')")
    @GetMapping("/list/{id}")
    public CommonResult<List<ItemNodeVo>> list(@PathVariable("id") Long scheId) {
        List<ItemNodeVo>  itemNodeVos = evaluationItemService.getListByScheId(scheId);
        return CommonResult.success(itemNodeVos);
    }

    @ApiOperation("info/{id} => 获取考评项")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:query')")
    @GetMapping("/info/{id}")
    public CommonResult<ItemNodeVo> info(@PathVariable("id") Long teitId) {
        ItemNodeVo entity = this.evaluationItemService.getById(teitId);
        return CommonResult.success(entity);
    }

    @ApiOperation("update/{id} => 修改指定的考评项")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:edit')")
    @SysLog(title = "修改指定的考评项", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/update/{id}")
    public CommonResult<Integer> update(@PathVariable("id") Long id, @RequestBody ItemNodeVo itemNodeVo) {
        int count = this.evaluationItemService.update(id, itemNodeVo);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("create => 新建考评项")
    @PostMapping(value = "/create")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:add')")
    @SysLog(title = "新建考评项", businessType = BusinessType.INSERT)
    public CommonResult<Integer> create(@RequestBody ItemNodeVo scheme) {
        int count = this.evaluationItemService.create(scheme);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("deleteByIds/{ids} => 删除指定考评项")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:remove')")
    @SysLog(title = "删除指定考评方案", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/deleteByIds/{ids}")
    public CommonResult<Integer> deleteByIds(@PathVariable Long[] ids) {
        int count = this.evaluationItemService.deleteByIds(ids);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

}
